const Koa = require('koa');
// const bodyParser = require('koa-bodyparser')
const bodyParser = require('koa-body')

const router = require('./server/router');
const static = require('./server/static');


const app = new Koa();

app
  .use(static) //静态资源服务
  .use(bodyParser()) //解析post请求参数
  .use(async (ctx, next) => { //响应头设置
    ctx.response.set("Access-Control-Allow-Origin", "*");
    ctx.response.set("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS")
    ctx.response.set("Access-Control-Allow-Headers", "Content-Type");
    ctx.response.set("Content-Type", "application/json; charset=utf-8");
    await next();
  })
  .use(router.routes()) //添加路由
  .use(router.allowedMethods()) //路由方法
  .listen(7000); //监听端口